"""
"""
from pml import PML


class DefaultObjectFunctions:
    @staticmethod
    def tp_print(frame, this: 'typeobject', position):
        return PML.object.ChangeObject.PMLString_FromStr(f'<Object {this.name}>')

    @staticmethod
    def nullFunction(frame, this, position, *args):
        return PML.object.ChangeObject.PMLNull_FromNone(None)

# PML interpreter creates as it define file new object the object.
class typeobject:
    def __init__(self, name: str = '<object>'):
        self.name: str = name
        self.methods = {
            '__init__': DefaultObjectFunctions.nullFunction
        }
        self.staticMethods = {}

    def getObject(self):
        return self

    def getStaticMember(self, name: str):
        try:
            return self.staticMethods[name]
        except KeyError:
            raise NameError(name)

    def getMember(self, member):
        raise NameError

    def Copy(self):
        obj = typeobject(self.name)
        obj.methods = self.methods.copy()
        obj.staticMethods = self.staticMethods.copy()
        return obj

# The object is a specific.
class PMTypeObject:
    def __init__(self, obj: typeobject):
        self.obj = obj
    def __repr__(self):
        return self.obj.__repr__()
    def __str__(self):
        return self.obj.__str__()
    def __iter__(self):
        return iter(self.obj)
    def __next__(self):
        return next(self.obj)
    def __hash__(self):
        return self.obj.__hash__()
    def __len__(self):
        return self.obj.__len__()
    def __reduce__(self):
        return self.obj.__reduce__()

    def __eq__(self, other):
        return self.obj == other

    def getMember(self, name: str):
        try:
            return self.obj.methods[name]
        except KeyError:
            raise NameError(name)

    def getStaticMember(self, name: str):
        try:
            return self.obj.staticMethods[name]
        except KeyError:
            raise NameError(name)
